<template>
	<view class="box">
		<view class="text">¥: {{ rechargeMoney }}元</view>
		<QRCode v-if="url" :param="param" :text="url" type="WX"
			logo="https://feishazoushi.cn/appImages/images/home/wd/WX.png" />
	</view>
</template>

<script>
import QRCode from '@/components/qrcode/qrcode.vue';

export default {
	components: {
		QRCode,
	},
	data() {
		return {
			url: '',
			rechargeMoney: "",
			param: '',
			payPhone: '',
			payisChannel: 2,
			query: ''
		}
	},
	onLoad(option) {
		this.rechargeMoney = option.rechargeMoney
		this.payPhone = option.payPhone
		this.payisChannel = option.payisChannel
		this.query = `payPhone=${this.payPhone}&payMore=${this.rechargeMoney}&payisChannel=${this.payisChannel}`

		let param = {
			type: 5,
			miniProgram: {
				id: "gh_fa047443538a",
				path: `pages/userPay/index?payPhone=${this.payPhone}&payMore=${this.rechargeMoney}&payisChannel=${this.payisChannel}&type=WX`,
				type: 2, //0-正式版；1-测试版；2-体验版。默认值0
				webUrl: "https://feishazoushi.cn/gw/",
			},
		};
		this.param = param
		if (this.query) {
			this.getUrl()
		}
	},
	methods: {
		getUrl() {
			uni.request({
				url: this.baseUrl + "/system/generateUrlLink",
				method: "POST",
				data: {
					path: 'pages/userPay/index',
					query: this.query
				},
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						let data = JSON.parse(res.data.data)
						console.log("res", data);
						this.url = data.url_link
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'error',
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					uni.showToast({
						title: res.errMsg,
						icon: 'error',
					});
				},
			});
		}
	},
};
</script>

<style lang="scss">
.box {
	padding-top: 88rpx;

	.text {
		text-align: center;
		font-size: 40rpx;
	}
}
</style>